#
# Copyright 2023 The Kumo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################
# system pthread and rt, dl
############################################################
set(KMCMAKE_SYSTEM_DYLINK)
if (APPLE)
    find_library(CoreFoundation CoreFoundation)
    list(APPEND KMCMAKE_SYSTEM_DYLINK ${CoreFoundation} pthread)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
    list(APPEND KMCMAKE_SYSTEM_DYLINK rt dl pthread)
endif ()

if (KMCMAKE_BUILD_TEST)
    enable_testing()
    #include(require_gtest)
    #include(require_gmock)
    #include(require_doctest)
endif (KMCMAKE_BUILD_TEST)

if (KMCMAKE_BUILD_BENCHMARK)
    #include(require_benchmark)
endif ()

find_package(Threads REQUIRED)
find_package(DuckDB REQUIRED)
find_package(
        ICU
        COMPONENTS
        data
        i18n
        io
        uc
        tu REQUIRED)

set(BOOST_INCLUDE_LIBRARIES
        atomic
        context
        date_time
        filesystem
        program_options
        circular_buffer
        uuid
        regex
        system
        thread)

find_package(Boost 1.77.0 COMPONENTS ${BOOST_INCLUDE_LIBRARIES} REQUIRED)

find_package(BISON 3.0.4 REQUIRED)
find_package(FLEX 2.5.13 REQUIRED)
find_package(double-conversion 3.1.5 REQUIRED)
find_package(re2 REQUIRED)
find_package(melon CONFIG REQUIRED)
find_package(simdjson REQUIRED)
find_package(Protobuf REQUIRED)
find_package(ksimd REQUIRED)
find_package(Thrift REQUIRED)
find_library(libstemmer_LIB NAMES libstemmer.a)
if(NOT libstemmer_LIB)
    message(FATAL_ERROR "libstemmer not found")
endif ()

include_directories(${Protobuf_INCLUDE_DIRS})

if (Protobuf_VERSION GREATER 4.21)
    # required by absl
    find_package(absl REQUIRED CONFIG)
    set(protobuf_ABSL_USED_TARGETS
            absl::absl_check
            absl::absl_log
            absl::algorithm
            absl::base
            absl::bind_front
            absl::bits
            absl::btree
            absl::cleanup
            absl::cord
            absl::core_headers
            absl::debugging
            absl::die_if_null
            absl::dynamic_annotations
            absl::flags
            absl::flat_hash_map
            absl::flat_hash_set
            absl::function_ref
            absl::hash
            absl::layout
            absl::log_initialize
            absl::log_severity
            absl::memory
            absl::node_hash_map
            absl::node_hash_set
            absl::optional
            absl::span
            absl::status
            absl::statusor
            absl::strings
            absl::synchronization
            absl::time
            absl::type_traits
            absl::utility
            absl::variant
            )
endif ()
find_package(GEOS REQUIRED)
find_package(ZLIB REQUIRED)
find_package(lz4 REQUIRED)
find_package(lzo2 REQUIRED)
find_package(zstd REQUIRED)
find_package(Snappy REQUIRED)
find_package(fmt REQUIRED)
find_package(merak REQUIRED)
find_package(turbo REQUIRED)
find_package(Arrow REQUIRED)
############################################################
#
# add you libs to the KMCMAKE_DEPS_LINK variable eg as turbo
# so you can and system pthread and rt, dl already add to
# KMCMAKE_SYSTEM_DYLINK, using it for fun.
##########################################################
set(KMCMAKE_DEPS_LINK
        #${TURBO_LIB}
        protobuf::libprotobuf
        ${protobuf_ABSL_USED_TARGETS}
        protobuf::libprotoc
        duckdb_static
        ${libstemmer_LIB}
        merak::merak_static
        turbo::turbo_static
        Melon::melon
        GEOS::geos
        thrift::thrift
        Arrow::arrow_static
        re2::re2
        lz4::lz4
        lzo2::lzo2
        simdjson::simdjson
        zstd::libzstd_static
        ZLIB::ZLIB
        double-conversion::double-conversion
        ${KMCMAKE_SYSTEM_DYLINK}
        )
list(REMOVE_DUPLICATES KMCMAKE_DEPS_LINK)
kmcmake_print_list_label("Denpendcies:" KMCMAKE_DEPS_LINK)





